package com.itheima.case1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer> {
    ArrayList<Integer> list;
    public MyCallable(ArrayList<Integer> list){
        this.list = list;
    }

    public Integer call() throws Exception {
                ArrayList<Integer> boxList = new ArrayList<>();
        while(true){
            synchronized (MyCallable.class){
                if(list.size() == 0){
                    System.out.println(Thread.currentThread().getName()+":"+boxList);
                    if(boxList.size() > 0) {
                        return Collections.max(boxList);
                    }else{
                        return null;
                    }
                }else{
                    Collections.shuffle(list);
                    boxList.add(list.remove(0));
                }
                Thread.sleep(100);
            }
        }

    }

}
